﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace WinDataInspector.Validation
{
    class HexValidator : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            // Here you make your validation using the value object.
            // If you want to check if the object is only numbers you can
            // Use some built-in method
            string input = (string)value;

            input = Regex.Replace(input, "^0[xX]", String.Empty);

            int output = 0;

            bool result = Int32.TryParse(input, System.Globalization.NumberStyles.HexNumber, null, out output);
            
            if (result) return new ValidationResult(true, null);
            else return new ValidationResult(false, "Invalid hex value");
        }
    }
}
